package cn.youyeku.zsxh.ui.List;

import android.content.Context;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * Created by youye on 17-4-14.
 */

public abstract  class CommonAdapter extends BaseAdapter {

    private Context context;
    private SparseBooleanArray datas;
    private LayoutInflater inflater;
    int listResId;

    /**
     * 初始化
     * @param context
     * 上下文
     * @param datas
     * 数据集合
     * @param listResId
     * 布局文件id
     */
    public CommonAdapter(Context context, SparseBooleanArray datas,int listResId) {
        this.context = context;
        this.datas = datas;
        inflater= LayoutInflater.from(context);
        this.listResId=listResId;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Boolean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public  View getView(int position, View convertView, ViewGroup parent){

        ViewHolder holder = ViewHolder.getInstance(context, convertView,
                parent, listResId, position);

        //抽象方法让用户来实现；
        convert(holder,getItem(position));

        return holder.getConvertView();

    }

    public abstract  void convert(ViewHolder holder,Boolean t);

}